package com.example.douyin.home;

import androidx.lifecycle.MutableLiveData;

import com.example.lib_base_mvvm.baseMVVM.BaseRepo.BaseRepo;
import com.example.lib_base_mvvm.entity.PinglunEntity;
import com.example.lib_base_mvvm.entity.ResultEntity;
import com.example.lib_base_mvvm.entity.VideoEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class HomeRepo extends BaseRepo {

    public void video(int page, int size, MutableLiveData<VideoEntity> success,MutableLiveData<String> fail){
        apiServer.video(page, size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    //执行点赞的请求
    public void love(int videoId, MutableLiveData<ResultEntity> success,MutableLiveData<String> fail){
        apiServer.love(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void nolove(int videoId, MutableLiveData<ResultEntity> success,MutableLiveData<String> fail){
        apiServer.nolove(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void guanzhu(RequestBody body,MutableLiveData<ResultEntity> success,MutableLiveData<String> fail){
        apiServer.guanzhu(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                            success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void pinglun(int videoId, MutableLiveData<PinglunEntity> success,MutableLiveData<String> fail){
        apiServer.pinglun(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PinglunEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PinglunEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void sendpinglun(RequestBody body,MutableLiveData<PinglunEntity> success,MutableLiveData<String> fail){
        apiServer.sendpinglun(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PinglunEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PinglunEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
